package com.enjoy.ui;

import java.lang.reflect.Field;
import java.util.List;

import com.enjoy.R;
import com.enjoy.po.Event;
import com.enjoy.ui.Event_list.ListAdapter;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;

public class Events extends TabActivity {
	private TabHost tabHost;
	private TabWidget tabWidget;
	Field mBottomLeftStrip;
	Field mBottomRightStrip;
	
	
	private List<Event> list;
    private ListAdapter adapter;
	ListView listView; 
	Button refreshButton;
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.events);
        
        makeTab();
    }
    
    public void makeTab(){
    	if(this.tabHost == null){
	    	tabHost = getTabHost();
	        tabWidget = getTabWidget();
	        tabHost.setup();
	        tabHost.bringToFront();
	        
	        TabSpec myEvents = tabHost.newTabSpec("myEvents");
	        TabSpec allEvents = tabHost.newTabSpec("myEvents");
	        TabSpec someEvents = tabHost.newTabSpec("someEvents");
	        
	        myEvents.setIndicator("myEvents",null).setContent(R.layout.event_list);
	        allEvents.setIndicator("allEvents",null).setContent(new Intent(this,Login.class));
	        someEvents.setIndicator("someEvents",null).setContent(new Intent(this,SignUp.class));
	        
	        tabHost.addTab(myEvents);
	        tabHost.addTab(allEvents);
	        tabHost.addTab(someEvents);
	        
	       
	        
//	        if (Integer.valueOf(Build.VERSION.SDK) <= 7) {
//				try {
//					mBottomLeftStrip = tabWidget.getClass().getDeclaredField ("mBottomLeftStrip");
//					mBottomRightStrip = tabWidget.getClass().getDeclaredField ("mBottomRightStrip");
//					if(!mBottomLeftStrip.isAccessible()) {
//						mBottomLeftStrip.setAccessible(true);
//					}
//					if(!mBottomRightStrip.isAccessible()){
//						mBottomRightStrip.setAccessible(true);
//					}
//					mBottomLeftStrip.set(tabWidget, getResources().getDrawable (R.drawable.linee));
//					mBottomRightStrip.set(tabWidget, getResources().getDrawable (R.drawable.linee));
//
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			} else {
//				try {
//					mBottomLeftStrip = tabWidget.getClass().getDeclaredField("mLeftStrip");
//					mBottomRightStrip = tabWidget.getClass().getDeclaredField("mRightStrip");
//					if (!mBottomLeftStrip.isAccessible()) {
//						mBottomLeftStrip.setAccessible(true);
//					}
//					if (!mBottomRightStrip.isAccessible()) {
//						mBottomRightStrip.setAccessible(true);
//					}
//					mBottomLeftStrip.set(tabWidget, getResources().getDrawable(R.drawable.linee));
//					mBottomRightStrip.set(tabWidget, getResources().getDrawable(R.drawable.linee));
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			}
	        
			for (int i =0; i <tabWidget.getChildCount(); i++) {
				
				View vvv = tabWidget.getChildAt(i);
				if(tabHost.getCurrentTab()==i){
					vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.focus));
				}
				else {
					vvv.setBackgroundDrawable(null);
				}
			}
			
			tabHost.setOnTabChangedListener(new OnTabChangeListener(){
	
				@Override
				public void onTabChanged(String tabId) {
					for (int i =0; i < tabWidget.getChildCount(); i++) {
						View vvv = tabWidget.getChildAt(i);
						if(tabHost.getCurrentTab()==i){
							vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.focus));
						}
						else {
							vvv.setBackgroundDrawable(null);
						}
						
						switch (tabHost.getCurrentTab()) {
						case 0:
							
						break;
						case 1:
						
						break;
						case 2:
						
						break;
						default:
						break;
						}
						
						
					}
				}
			});
    	}
    }
}